<!DOCTYPE html>
<html>
<head>
	<title>vue</title>
	<meta charset="UTF-8">
	<script src="./vue.js"></script>
</head>
<body>
	<div id="app">
		<input type="text" v-model="inputValue">
		<button v-on:click="handleBtnClick" :title="message">提交</button>
		<ul>
			<todo-item :content="item"
					   :index="index"
					   v-for="(item, index) in list" @delete="handleItemDelete">
			</todo-item>
		</ul>
	</div>

	<script>
		// Vue.component("TodoItem", {
		// 	props: ['content'],
		// 	template: "<li>{{content}}</li>",
		// })

		var TodoItem = {
			props: ['content', 'index'],
			template: `<li @click='handleItemClick'>{{content}}</li>`,
			methods: {
				handleItemClick: function () {
					this.$emit('delete', this.index)
				}
			}
		}

		var app = new Vue({
			el: '#app',
			data: {
				list: [],
				inputValue: 'try',
				message: new Date(),
				// message: '页面加载于 ' + new Date().toLocaleString()
			},
			methods: {
				handleBtnClick: function () {
					this.list.push(this.inputValue)
					this.inputValue = ''
				},
				handleItemDelete: function (index) {
					this.list.splice(index, 1, '<br>')
				}
			},
			components: {
				TodoItem
			}
		})

		app.$watch('inputValue', function (newVal, oldVal) {
			console.log(oldVal, newVal)
		})


	</script>

</body>
</html>